package mest.controller.Modeling;

import com.alibaba.fastjson.JSON;
import mest.VO.Modeling.WarehouseSaveFile_manytomany.savefileVO;
import mest.entity.warehouse_file;
import mest.entity.warehousesave_manytomany;
import mest.service.Modeling.IwarehouseFileService;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @Description
 * @auther Machenike
 * @create 2019-11-16 1:22
 */
@RestController
@CrossOrigin
@RequestMapping(value = "/warehouseFile")
public class warehouseFile {
    @Resource
    private IwarehouseFileService ipfs;

    @RequestMapping(value = "/insert")
    public String insert(warehouse_file wt) {

        int i = ipfs.insertWarehouseFileType(wt);
        if (i >= 1)
            return JSON.toJSONString("添加成功");
        else
            return JSON.toJSONString("添加失败");
    }

    @RequestMapping(value = "/baseSelect", produces = {"application/json;charset=utf-8", "text/plain;charset=utf-8"})
    public String baseSelect(int index, int pageSize) {

        List<warehouse_file> warehouseFilePage = ipfs.findWarehouseFilePage(index, pageSize);
        int i = ipfs.selectCount();
        Map map = new HashMap();
        map.put("code", 0);
        map.put("msg", "");
        map.put("count", i);
        map.put("data", warehouseFilePage);
        return JSON.toJSONString(map);
    }

    //    toolbar查看bom详情
    @RequestMapping(value = "/saveFileDetail", produces = {"application/json;charset=utf-8", "text/plain;charset=utf-8"})
    public String saveFileDetail(int wfId, int index, int pageSize) {

        System.out.println(wfId);
        List<savefileVO> savefileByWFId = ipfs.findSaveByWFId(wfId, index, pageSize);
        int i = ipfs.SaveCount(wfId);
        Map map = new HashMap();
        map.put("code", 0);
        map.put("msg", "");
        map.put("count", i);
        map.put("data", savefileByWFId);
        return JSON.toJSONString(map);
    }

    //    toolbar添加save
    @RequestMapping(value="/addSave", produces = {"application/json;charset=utf-8", "text/plain;charset=utf-8"})
    public String addBom(warehousesave_manytomany wsmtm){

        int i = ipfs.insertManytomany_WarehouseAndSave(wsmtm);
        if (i >= 1)
            return JSON.toJSONString("添加成功");
        else
            return JSON.toJSONString("添加失败");
    }

    // toolbar 修改save
    @RequestMapping(value="/updateSave", produces = {"application/json;charset=utf-8", "text/plain;charset=utf-8"})
    public String updateBom(savefileVO wsmtm){

        int i = ipfs.updateManytomany_WarehouseAndSave(wsmtm);
        if (i >= 1)
            return JSON.toJSONString("修改成功");
        else
            return JSON.toJSONString("修改失败");
    }
}
